#include <bits/stdc++.h>
using namespace std;
long Fibonacci(unsigned int n,vector<int>& init)
{

    if (n == 0)
        return init[0];
    if (n == 1)
        return init[1];
    if (n == 2)
        return init[2];
    long FibsubOne = init[0];
    long FibsubTwo = init[1];
    long FibsubThree = init[2];
    long Fib=0 ;
    int i = 3;
    while (i <= n)
    {

        if(Fib>9&&Fib<100)
        {
            FibsubThree = Fib%10;
            FibsubOne = FibsubTwo;
            FibsubTwo = Fib/10;
        }
        Fib = FibsubOne+FibsubTwo+FibsubThree;
        FibsubOne = FibsubTwo;//最低位
        FibsubTwo = FibsubThree;//中间位
        FibsubThree = Fib;//最高位
        i++;
    }
    return Fib;
}
int main() {
    vector<int>a = {1,1,1};
    int count = 0;
    int i = 0;
    int n;
    cin>>n;
    while(i<2*n)
    {
        int num = Fibonacci(i++,a);
        if(num/10>0)
            count+=2;
        else
            count+=1;
        if(count==n)
        {
            cout<<num%10;
            break;
        }

    }
    return 0;
}